package ${servicePackage}.impl;

import com.ajavaer.framework.common.message.Message;
import com.ajavaer.framework.common.tools.ObjectTools;
import ${poPackage}.${className};
import ${daoPackage}.${className}DAO;
import ${servicePackage}.${className}Service;
import com.ajavaer.framework.common.validate.Validation;
import com.ajavaer.framework.core.orm.service.impl.BaseServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;

@Service
@Transactional(rollbackFor = Exception.class)
public class ${className}ServiceImpl extends BaseServiceImpl<${className}, ${pkType}> implements ${className}Service {

    private ${className}DAO ${className?uncap_first}DAO;

    @Autowired
    public ${className}ServiceImpl(${className}DAO ${className?uncap_first}DAO) {
        super(${className?uncap_first}DAO);
        this.${className?uncap_first}DAO = ${className?uncap_first}DAO;
    }

    @Override
    public Message save${className}(${className} ${className?uncap_first}) {
        if (ObjectTools.isBlank(${className?uncap_first})) {
            return Message.fail("要保存的对象不能为空");
        }
        Validation.assertSuccess(${className?uncap_first});
        if (ObjectTools.isNotBlank(${className?uncap_first}.getId())) {
            //更新
            ${className} db${className} = getById(${className?uncap_first}.getId());
            if (db${className} == null) {
                return Message.fail("对应数据不存在");
            }
        }
        saveOrUpdate(${className?uncap_first});
        return Message.success("保存成功");
    }
}